              package com.java.diagnostics.visualizer.displayer.html;
              
              import com.java.diagnostics.visualizer.coredisplayers.util.Messages;
              import com.java.diagnostics.visualizer.data.AggregateData;
              import com.java.diagnostics.visualizer.data.DataSet;
              import com.java.diagnostics.visualizer.data.DomainData;
              import com.java.diagnostics.visualizer.data.ids.ID;
              import com.java.diagnostics.visualizer.impl.factory.LogFactory;
              import java.io.BufferedWriter;
              import java.io.File;
              import java.io.IOException;
              import java.util.logging.Logger;
              
              public abstract class DataWriter
              {
                private static final String REPRESENTATIVE = Messages.getString("DataWriter.representative");
              
                protected static final String VARIANT = Messages.getString("HTMLReportDisplayer.variant");
              
                protected static final String NA = Messages.getString("DataWriter.data.not.available");
                private static final String TD_HEADER_OPEN = "<td class=\"header\" rowspan=\"";
                private static final String TD_HEADER_OPEN_HORIZONTAL = "<td class=\"header\" colspan=\"";
                private static final String ANCHOR_OPEN = "<a tabindex=\"0\"  name=\"";
                private static final String ANGLE_BRACKET_CLOSE = "\">";
                private static final String PARAGRAPH_COMPLETE = "<p/>";
                private static final String ANCHOR_CLOSE = "</a>";
                protected static final String CLOSE_ANGLE_BRACKET = "\">";
                protected static final String EMPTY_STRING = "";
                private static final String SPACE = " ";
                protected static final double FRACTION_OF_WINDOW_WIDTH_TO_FILL = 0.7D;
                protected static final double HEIGHT_WIDTH_RATIO = 0.75D;
                protected static final String NEWLINE = System.getProperty("line.separator");
                private static final String TABLE_ROW_CLOSE = "</tr>";
                private static final String TABLE_ROW_OPEN = NEWLINE + " <tr>";
              
                private static final String DATA_HEADER_CLOSE = "</h2> " + NEWLINE;
              
                private static final String DATA_HEADER_OPEN = "<h2> " + NEWLINE;
                private static final String TABLE_CLOSE = "</table>";
                private static final String TABLE_OPEN = "<table class=\"results\">";
                private static final String TABLE_CELL_CLOSE = "</td>";
                private static final String TABLE_CELL_OPEN = "<td class=\"results\">";
                private static final String TABLE_CELL_OPEN_ODD = "<td class=\"resultsodd\">";
                private static final String TABLE_HEADER_CLOSE = "</td>";
                protected static final boolean SHOW_ONLY_TOP_LEVEL_DATA = true;
                protected static final boolean SHOW_COMMENTS = false;
                protected static final int MIN_NUMBER_TO_SHOW_LABEL = 1;
                protected static final Logger TRACE = LogFactory.getTrace(DataWriter.class);
                protected static final String NBSP = "&nbsp;";
                protected DataSet dataSet = null;
                protected File directory;
                protected ID id;
                protected BufferedWriter buffer;
                protected AggregateData representativeData;
                protected boolean usingTable;
                protected boolean oddRow = false;
                protected HTMLReportPreferencesHelper preferencesHelper;
              
                protected DataWriter(DataSet dataSet, ID id, AggregateData representativeData, BufferedWriter buffer)
                {
                  this.dataSet = dataSet;
                  this.id = id;
                  this.buffer = buffer;
                  this.representativeData = representativeData;
                  this.preferencesHelper = new HTMLReportPreferencesHelper();
                }
              
                public void write() throws IOException
                {
                  if (this.representativeData.getData(this.id) != null)
                    writeData();
                }
              
                protected abstract void writeData()
                  throws IOException;
              
                protected void closeTable() throws IOException
                {
                  this.buffer.write("</table>");
                  this.buffer.write(NEWLINE);
                }
              
                protected void closeRow() throws IOException
                {
                  if (this.usingTable)
                    this.buffer.write("</tr>");
                }
              
                protected void openRow()
                  throws IOException
                {
                  if (this.usingTable)
                    this.buffer.write(TABLE_ROW_OPEN);
                }
              
                protected void addTableCell(String contents)
                  throws IOException
                {
                  openCell();
                  this.buffer.write(contents);
                  closeCell();
                }
              
                protected void closeCell() throws IOException {
                  this.buffer.write("</td>");
                }
              
                protected void openCell() throws IOException {
                  if (this.oddRow)
                    this.buffer.write("<td class=\"resultsodd\">");
                  else
                    this.buffer.write("<td class=\"results\">");
                }
              
                protected void addTableHeader(String label, int rowspan)
                  throws IOException
                {
                  this.buffer.write("<td class=\"header\" rowspan=\"" + rowspan + "\">");
                  this.buffer.write(label);
                  this.buffer.write("</td>");
                }
              
                protected void addHorizontalTableHeader(String label, int colspan)
                  throws IOException
                {
                  this.buffer.write("<td class=\"header\" colspan=\"" + colspan + "\">");
                  this.buffer.write(label);
                  this.buffer.write("</td>");
                }
              
                private void addHeading(String label, String displayName) throws IOException
                {
                  this.buffer.write(DATA_HEADER_OPEN);
                  this.buffer.write(displayName);
                  this.buffer.write("<a tabindex=\"0\"  name=\"");
                  this.buffer.write(stripSpaces(label));
                  this.buffer.write("\">");
                  this.buffer.write("</a>");
                  this.buffer.write(DATA_HEADER_CLOSE);
                }
              
                private String stripSpaces(String string)
                {
                  return string.replaceAll(" ", "");
                }
              
                protected void openTable() throws IOException
                {
                  newLine();
                  this.buffer.write("<table class=\"results\">");
                }
              
                protected void newLine() throws IOException
                {
                  this.buffer.write(NEWLINE);
                  this.buffer.write("<p/>");
                }
              
                protected void addDataHeading() throws IOException {
                  String label = this.representativeData.getData(this.id).getLabel();
                  String displayName = this.representativeData.getData(this.id).getDisplayName();
                  addHeading(label, displayName);
                }
              }

